/************************************

DESCRIPTION: This program produces the means
  by subgroup for use in the balance statistic calculations.


************************************/

set more off
capture log close
clear all

set matsize 10000

global origData "N:\MedicareClaims-P045601-BE"
global dataIn "N:\MedicareClaims-P045601-BE\Work\hosp_retro\health_out\Data-In\"
global dataOut "N:\MedicareClaims-P045601-BE\Work\hosp_retro\health_out\Data-Out"
global dpath "N:\MedicareClaims-P045601-BE\Work\ay_data"
global dataProp "N:\MedicareClaims-P045601-BE\Work\hosp_retro\health_out\Data-Out\PropScore\Patients"
global logs "N:\MedicareClaims-P045601-BE\Work\hosp_retro\health_out\Logs\PropScore\Patients"
global dpath "N:\MedicareClaims-P045601-BE\Work\ay_data"
global skapath "N:\MedicareClaims-P045601-BE\Work\ska"
global lpm "N:\MedicareClaims-P045601-BE\Work\hosp_retro\health_out\Program\PropensityScore\Patients\ResponsetoReferee\OtherPropScoreMethods\LPM"
global output

adopath +  "N:/SIL-Common/estout"
adopath +  "N:/SIL-Common/outreg2"
adopath +  "N:/SIL-Common/reghdfe-master/package"

log using "./8b.XMeans.log", replace

*Data
use  "$lpm/LPManalysis.dta"
drop if year(quarter)==2005
drop if age<64
*Various sample restrictions performed, here:
* (1) limit to age >64
* (2) limit to quarter >= 184
* (3) limit to year > 2005

sort BENE_ID quarter

gen age6574=age<75
gen age7584=age>=75 & age<85
gen age8594=age>=85 & age<95
gen age95plus =age>=95 

drop if mxdiabetes_p_all ==.
drop if lor==.
drop if fs5==.
drop if urbanrural1==.

drop mndate physcnt sex* race* zip* new* docid firmct ssa* county* fips* dropflag 

log close
log using "./8.XMeans.log", replace
drop if q_of_merger==. & vmerger==1

 
*All
summ if ( merger_seen==0 | merger_seen==.), sep(0)
summ if merger_seen==1, sep(0)
summ if merger_seen==0, sep(0)

*Diabetes
summ if mxdiabetes_p_all ==1 & ( merger_seen==0 | merger_seen==. ), sep(0)
summ if mxdiabetes_p_all ==1 & merger_seen==1, sep(0)
summ if mxdiabetes_p_all ==1 & merger_seen==0, sep(0)

*Hypertension
summ if mxhypertension_p_all ==1 & ( merger_seen==0 | merger_seen==.), sep(0)
summ if mxhypertension_p_all ==1 & merger_seen==1, sep(0)
summ if mxhypertension_p_all ==1 & merger_seen==0, sep(0)
 
 